<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>会议统计</title>
    <th:block th:include="include :: header('签到统计')"/>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <style type="text/css">
        .table {
            margin-bottom: 0 !important;
        }
        /* 移除首行上边框 */
        .table>tbody>tr:first-child>td {
            border-top: none;
        }
        .panel-body {
            padding: 5px !important;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>会议统计信息</h2>
    <div class="row">
        <div class="col-md-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">参会情况统计</h3>
                </div>
                <div class="panel-body">
                    <table class="table">
                        <tr>
                            <td>应到人数：</td>
                            <td><span th:text="${meeting.meetingPeople}">0</span></td>
                        </tr>
                        <tr>
                            <td>实到人数：</td>
                            <td><span th:text="${meeting.signPeople}">0</span></td>
                        </tr>
                        <tr>
                            <td>请假人数：</td>
                            <td><span th:text="${meeting.leavePeople}">0</span></td>
                        </tr>
                        <tr>
                            <td>缺席人数：</td>
                            <td><span th:text="${meeting.absentPeople}">0</span></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-8">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">请假类型统计</h3>
                </div>
                <div class="panel-body">
                    <table class="table">
                        <tr th:each="item, idx : ${leaveList}" th:if="${idx.index % 2 == 0}">
                            <!-- 第一列：当前项的标题 -->
                            <td th:text="${item.name}">标题1</td>
                            <!-- 第二列：当前项的数值 -->
                            <td th:text="${item.value}">数值1</td>
                            <!-- 只在奇数行显示这两列（第二和第四列）并与前一行合并 -->
                            <td th:if="${idx.index % 2 == 1}" th:text="${item.name}"></td>
                            <td th:if="${idx.index % 2 == 1}" th:text="${item.value}"></td>

                            <!-- 第三列：下一项的标题（判断是否存在） -->
                            <td th:if="${idx.index + 1 < leaveList.size()}"
                                th:text="${leaveList[idx.index + 1].name}">标题2</td>
                            <td th:unless="${idx.index + 1 < leaveList.size()}">-</td>

                            <!-- 第四列：下一项的数值（判断是否存在） -->
                            <td th:if="${idx.index + 1 < leaveList.size()}"
                                th:text="${leaveList[idx.index + 1].value}">数值2</td>
                            <td th:unless="${idx.index + 1 < leaveList.size()}">-</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">缺席原因分类</h3>
                </div>
                <div class="panel-body">
                    <div id="pieChart" style="width: 100%;height:300px;"></div>
                </div>
            </div>
        </div>
    </div>
    <!--<div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">参会人员列表</h3>
                </div>
                <div class="panel-body">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>姓名</th>
                            <th>手机号</th>
                            <th>是否参加</th>
                            <th>请假类别</th>
                            <th>请假原因</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="item : ${signInRecordList}">
                            <td th:text="${item.realname}"></td>
                            <td th:text="${item.phone}"></td>
                            <td th:text="${item.attendFlag == 1 ? '是' : '否'}"></td>
                            <td th:text="${item.leaveType == 0 ? '事假' : (item.leaveType == 1 ? '病假' : (item.leaveType == 2 ? '年假' : (item.leaveType == 3 ? '调休' : '其他')))}"></td>
                            <td th:text="${item.leaveReason}"></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>-->
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/js/echarts.min.js?v=6.0.0}"></script>
<script>
    $(function () {
        // 初始化饼图
        var pieChart = echarts.init(document.getElementById('pieChart'));
        pieChart.setOption({
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: 'Direct',
                    type: 'bar',
                    barWidth: '60%',
                    label: {
                        show: true,
                        position: 'top',
                        color: '#333'
                    }
                }
            ]
        });
        var meetingId = [[${meetingId}]];
        // 从后端获取数据
        $.ajax({
            url: '/app/record/series/' + meetingId,
            type: 'POST',
            success: function (obj) {
                // 更新饼图数据
                var names = [];
                var values = [];
                obj.data.forEach(function (item) {
                    names.push(item.name);
                    values.push(item.value);
                });
                pieChart.setOption({
                    xAxis: [{
                        data: names
                    }],
                    series: [{
                        data: values
                    }]
                });

                // 更新参会人员列表
                /* var tbody = $('table.table-striped tbody');
                tbody.empty();
                $.each(data.list, function (i, item) {
                    tbody.append('<tr><td>' + item.name + '</td><td>' + item.phone + '</td><td>' +
                        (item.attendFlag == 1 ? '已签到' : '未签到') + '</td><td>' +
                        (item.leaveReason || '') + '</td></tr>');
                }); */
            }
        });
    });
</script>
</body>
</html>